package main

import (
	"fmt"
	"time"
)

func IntEq() (int, int, int) {
	// 初始化一个100万成员的int类型数组，全部存储偶数，最后一个数组存储：
	const num = 2000000
	coefficient := 1000
	var arrEven [num/2 + 1]int // 存储偶数100万+ 1个相等元素
	var arrOdd [num/2 + 1]int  // 存储偶数100万+ 1个相等元素

	var evenIndex = 0
	var oddIndex = 0

	for i := 1; i <= num; i++ {
		if i%2 == 0 {
			arrEven[evenIndex] = i * coefficient
			evenIndex++
		} else {
			arrOdd[oddIndex] = i * coefficient
			oddIndex++
		}
	}

	arrEven[evenIndex] = (num + 1) * coefficient
	arrOdd[oddIndex] = (num + 1) * coefficient

	var eqCounts = 0
	var eqVal = 0
	var neqCounts = 0

	for i := 0; i <= num/2; i++ {
		if arrEven[i] == arrOdd[i] {
			eqCounts++
			eqVal = arrOdd[i]
		} else {
			neqCounts++
		}
	}
	return neqCounts, eqCounts, eqVal
}

func main() {
	startTime := time.Now()
	var neqCounts, eqCounts, eqVal int
	for i := 0; i < 10; i++ {
		neqCounts, eqCounts, eqVal = IntEq()
	}

	// 两个100万成员的数组中，相等的个数： 1 相等值： 2000001000  不相等的个数： 1000000 单次耗时(ms)： 2
	fmt.Println("两个100万成员的数组中", " 不相等的个数：", neqCounts, " 相等的个数：", eqCounts, "相等值：", eqVal, "单次耗时(ms)：", time.Now().Sub(startTime).Milliseconds()/10)

}
